//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal static class UnknownElementHelper
    {
        public static IOfficeXmlSerializable Read(ReadContext c)
        {
            var ser = (IEnumerable<IOfficeInstanceProvider>) c.GetData(typeof (IOfficeInstanceProvider));
            IOfficeXmlSerializable result = null;
            if (ser != null)
            {
                foreach (IOfficeInstanceProvider provider in ser)
                {
                    result = provider.ReadInstance(c);
                    if (result != null)
                        return result;
                }
            }
            result = new DrawingInstanceProvider().ReadInstance(c);
            if (result != null )
                return result;
            if (result == null)
                result = new ExtensionElement();
            result.ReadXml(c);
            return result;
        }
    }
}